28th
JAN

DS18B20 & 1602 LCD I2C

Posted by M. 4Gani under Electronici:

Before I start, let’s of a quick review about the differences between DHT22 Temperature and Humidity sensor and DS18B20 Temperature sensor 1-Wire. (DHT22 vs. DS18B20)

سنسور دما دیجیتال DS18B20,  سنسور رطوبت و دما DHT22, دماسنج NTC

 

 

DHT22 vs. DS18B20 & NTC

DHT22 vs. DS18B20 & NTC

DHT22 is a digital temperature and humidity sensor.
DHT22 has a capacitive humidity  and a thermistor sensor and measures the surrounding air in one device.
The device only has a digital signal output (NOT any analog output).
The data can be read from the output every 2 seconds .
It comes in different technologies and forms.

DS18B20 Temperature Sensor

DS18B20 is 1-Wire interface Temperature sensor. This sensor has 3 pins and looks like a transistor.
The sensors only requires one port pin for communication and needs NO other external components to work.

Each individual device has its unique ID.
This ID consists of a 64-bit number (8 bytes). The microcontroller calls a unique ID and receive the carry data information in two bytes from the device.

All the other devices connected to the bus remain silent during their ID is not called.
The sending the data bytes for a DS18B20 takes about 750 msec.

The thermometer resolution of DS18B20 is programmable from 9 to 12 bits and it converts 12-bit temperature to digital in less than 750 ms.

For my project I decided to use a DS18B20 Sensor.

Components

– Arduino board
– DS18B20 Temperature Sensor module
– LCD1602 with serial interface

 

22nd
JAN

Clock with LCD 1602 & DS1307

Posted by M. 4Gani under Electronici:

Make a clock with DS1307 real clock module and 1602 16×2 LCD panel with back-panel to convert it to I2C protocol. (I2C راه اندازی با)
The time and date will be displayed in alphanumeric on LCD.

Clock with LCD 1602 16x2 & DS1307 real clock

Clock with LCD 1602 16×2 & DS1307

Device: LCD 1602 with back-panel  (نمایشگر LCD 16×2 کاراکتری دو سیمی)

The communication requires only two pins on the microcontroller bord: A4 and A5.
SDA: Analog 4
SCL: Analog5
VCC: 5V
GND: GND terminals
Contrast Adjust : has a built in potentiometer for contrast adjustment.
I2C Address: in my case is 0x27

You should see the LCD light up by starting, if it dose not happened, you may want to turn down the contrast of the LCD.

LCD has 2 lines, 16 character in each line and each character have 5-pixel in width and 8-pixel in height.
The LCD supports up to 8 custom characters numbered from 0 to 7.

The DS1307 Real time use also I2C Protocol to communicate with arduino.

Driver IC: I2C DS1307 Real Time Clock
SCL:
Analog 5  (clock line)
SDA: Analog 4   (data line)
Voltage: 3.3V to 5V
GND:  GND of Arduino
I2C Address: in my case was 0x68

Each device on the I2C bus has its own unique address. The LCD display used here has address 0x27.
You can use the scanner script to find  I2C addresses on arduino by using

The I2C address used by a device can be found with the sketch i2c_scanner

Scanning…
I2C device found at address 0x27 !
I2C device found at address 0x68 !
done

To drive LCD I’m using the LiquidCrystal_I2C library, which seems to be commonly used.

 

22nd

DCF77 Signal with Arduino

Posted by M. 4Gani under Electronic, Ring Clock Projecti:

The DCF77 signal is a puls-signal with AM modulation with carrier frequency 77.5kHz. It has a small bandwidth.

The carries include time and date information and will be transmitted in a simple binary-coded format by on-off modulation of the carriers.  (100ms/200ms)
The Signal time and date code include the following information:

  • year, month, day of month, day of week
  • hour, minute, second, summer time

DCF receiver module with antenna (Radio Controlled Clock)

This module comes in different variants and forms and receive the 77.5 kHz signal from Frankfurt and decodes and sends the data stream to the output. The output signal can be processed by a microcontroller.

The normal inputs/outputs on a DCF receiver module are:

TCON = Digital output of carrier signal
PON (if provided) usually grounded to GND to enable the receiver.
Operating voltage from  +2.5V to +5.5V

The data input should be connected to a digital pin of arduino that uses  a interrupt!


Arduino only has two pins that are digital and each uses an interrupt.

 

Digital 2 with INT0/0

DCF77 Code

DCF77 Code

Digital 3 with INT0/1

 

Digital output of carrier signal has to connected to D2 pin OR D3 pin.

If the device dose not received clear signal, make sure the DCF-Antenne is enough away from the interfering source. (At least 2m)
For example:

– Monitor, Computer
– Fluorescent lamps
– Power supplies

 

The amplitude of the carrier is reduced every second to 25% (- 6db) in order to code “0/1” logic by the length of the amplitude (simple pulse width signal). A 100ms lowering is a logic “0” whereas 200ms is a logic”1″.

Every second is equal to one bit. The start of a new time sequence is signalized by the 59th second after which there is not lowering of the amplitude.
The week-day is coded as “1” for Monday and “7” for  Sunday.

 

 

 

 


/*
 * DCFSignal.ino - DCF77 debug Example
*/

#include <DCF77.h>
#include <Time.h>
using namespace Utils;
 
#define DCF_PIN 2         // Connection pin to DCF 77 device
#define DCF_INTERRUPT 0   // Interrupt number associated with pin
#define BLINK_PIN 13

time_t time;
DCF77 DCF = DCF77(DCF_PIN, DCF_INTERRUPT);
 
void setup() {
  Serial.begin(9600);
  pinMode(DCF_PIN, INPUT);
  pinMode(BLINK_PIN, OUTPUT);
  Serial.println("Waiting for DCF77 time ... ");
  DCF.Start();
}
 
void loop() {
 delay(1000);
 time_t DCFtime = DCF.getTime(); // Check if new DCF77 time is available
 if (DCFtime!=0) {
    Serial.println("Time is updated");
    setTime(DCFtime);
 }
 digitalClockDisplay(DCFtime);
}
 
void digitalClockDisplay(){
   Serial.print(hour());
   printDigits(minute());
   printDigits(second());
   Serial.print(" ");   Serial.print(day());
   Serial.print(" ");   Serial.print(month());
   Serial.print(" ");   Serial.print(year()); 
   Serial.println(); 
}
 
void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

22nd

WS2812b & DS1307 with Arduino

Posted by M. 4Gani under Electronic, Ring Clock Projecti:

Making a ring wall clock with 1-meter long WS2812B LED strip with 60 RGB LEDs.  (ماژول LED RGB WS2812)

 LED WS2812 حلقه یا RGB LED WS2812b پنج متری

 For clock I used a DS1307, which contains a real-time clock.

WS2812b & DS1307

Driver IC: I2C DS1307 Real Time Clock
SCL Analog 5 (clock line)
SDA: Analog 4 (data line)
Voltage: +3.3V to +5V
GND: GND of Arduino
I2C Address: 0x68

NeoPixel – WS2812B LED strip
Length of strip: 1-meter
Number of LEDS per meter: 60
DIN: Digital 3
VCC: +5V to +12V
GND: GND on Arduino

 

The WS2812B LED strip is an addressable RGB LED strip and each LED includes an IC built in. This gives LEDs the possibility to communicate through one-wire interface.

Each LED has a data in/out pin and requires 24 bits (for each color 8 bits) of data to work.
The data is shifted in an 8 bit for green, 8 bits for red and finally 8 bits for blue intensity. (Total 3 byte)
Once a LED receives 24 bits data at its data-in pin, it forwards the data through its data-out pin to the next LED’s data-in pin.

The LED strip should be powered by an external 5V-12V power source.
by setting LED to maximal brightness, the maximum current of  LED will be ca. 50mA  (0,05 A x 60 LED’s = 3,0 A).

To reduce noise on strip you need to  add a 220 or 470 Ohm resistor between the arduino digital output pin and the strip data input pin.

Arduino libraries:
Adafruit’s Neopixel and RTClib

Demo Code



// include the library code
#include <Adafruit_NeoPixel.h> 

#define PIN 3
#define NUM_LEDS 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
RTC_DS1307 RTC;       // establish clock object

DateTime now;         // holds current clock time
byte hrs, mins, secs; 

int BLINK_PIN = 13;

void setup() {
  delay(1000);       // 1 second delay for recovery
  Serial.begin(9600);
  pinMode(BLINK_PIN, INPUT);
  if (!RTC.begin()) {
    Serial.println("Couldn't find RTC");
    while(1);
  }
  if (!RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
  Wire.begin();
  strip.begin();
  strip.show();       // Initialize all pixels to 'off'
  delay(500);
}

void loop() {
  DateTime now = RTC.now();
  secs = now.second();  // get seconds
  mins = now.minute();  // get minutes
  hrs = now.hour();     // get hours
  Serial.print("rtc:\t");
  Serial.print(now.year()); Serial.print("-");
  Serial.print(now.month()); Serial.print("-");
  Serial.print(now.day()); Serial.print(" ");
  Serial.print(hrs); Serial.print(":");
  Serial.print(mins); Serial.print(":");
  Serial.println(secs);  
  strip.setPixelColor(secs, 0x000055);
  strip.setPixelColor(mins, 0x550000);
  strip.setPixelColor(hrs, 0x005500);
  anyNr1(0, 0, 127); Serial.print("function: anyNr1\n");
  delay(200);
}

// fill
void anyNr1(byte red, byte green, byte blue) {
  int l;
  for(l=NUM_LEDS+1; l>secs; l--) {  
    LToRight(l, red, green, blue);
    for(int n=0; n<NUM_LEDS; n++) {
      if (n <= secs) {
        if (n != mins && n != hrs) strip.setPixelColor(n, 0x000055);
      } else {
        if (n != mins && n != hrs) strip.setPixelColor(n, strip.Color(0, 0, 0));
      }
    }
    strip.show();
  } 
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
  strip.setPixelColor(Pixel, strip.Color(red, green, blue));
}

void LToRight(int i, byte red, byte green, byte blue) {
  if (i != secs && i != mins && i != hrs) 
    setPixel(i, red, green, blue);  
  if (i+1 != secs && i+1 != mins && i+1 != hrs) 
    setPixel(i+1, red/5, green/5, blue/5); 
  if (i+2 != secs && i+2 != mins && i+2 != hrs) 
    setPixel(i+2, red/10, green/10, blue/10);
  if (i+3 != secs && i+3 != mins && i+3 != hrs) 
    setPixel(i+3, red/20, green/20, blue/20);
  if (i+4 != secs && i+4 != mins && i+4 != hrs) 
    setPixel(i+4, red/30, green/30, blue/30);
  if (i+5 != secs && i+5 != mins && i+5 != hrs) 
    setPixel(i+5, red/90, green/90, blue/90);
  strip.setPixelColor(secs, 0x000055);
  strip.setPixelColor(mins, 0x550000);
  strip.setPixelColor(hrs, 0x005500);
  strip.show();
  delay(20);
}

 

Continue…

 

22nd

LDR Sensor with Arduino

Posted by M. 4Gani under Electronic, Ring Clock Projecti:

The LDR Sensor also know as the Photo-resistor is basically a simple sensor that its resistance value changes with light. (resistance will lower with more light.)
The LDR isn’t very precise, so you can not get a LUX reading but it is good enough to tell the difference between light and shadow.
It can be used to make:

  • Automatic light dimmer
  • Light sensitive switch

    LDR Sensor with Arduino

    LDR Sensor with Arduino

Parts List

  • Arduino
  • LDR (also known as a photocell)
  • LED with 220 to 330 ohm resistor
  • 1K to 10K resistor (used with the LDR to setup a voltage divider)

Connections

The LDR is a special type of resistor which allows higher voltages to pass through it.
It means with a high intensity of light a low voltage passes.

The circuit based on a photo resistor that uses a resistor divider (4.7K to 10K) to allow the high impedance analog input to measure the voltage.
To get a voltage proportional to the photoresistor value, a resistor divider is necessary.

For demonstration we use an additional LED to digital pin 13 in series with the 220 ohm resistor.

Following formula is used  to calculate the voltage at A0 pin (Vout):

Vout=Vin*(R2/(R1+R2))

The voltage input (Vin) referenced to 5V expressed as a 10 bit value.
In other words 5V gets split up into 1024 levels, that is 5/1024 = 0.0048828125 volts per unit returned back.

ADC (analog-to-digital converter) of microcontroller converts and maps the analog value of the LDR from 0-5 volt to a value in 0-1023 range (digital 0-255).

 
/*
 Reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED Digital 13).
 http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int sensorPin = A0;    // select the input pin for the potentiometer and 10K pulldown
int ledPin = 13;       // select the pin for the LED

void setup() {
  Serial.begin(9600);     // serial connection
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the value from the sensor and converts to 0 to 1023 range by using ADC
  sensorValue = analogRead(sensorPin);
  digitalWrite(ledPin, HIGH);   // turn the ledPin on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // turn the ledPin off
  delay(1000);
  // map it to the range of the analog out
  int outputValue = map(sensorValue, 0, 1023, 0, 255);
  analogWrite(ledPin, outputValue); // change the analog out value
  // print the results to the Serial Monitor
  Serial.print("sensor = "); Serial.print(sensorValue);
  Serial.print("\t output = "); Serial.println(outputValue);
 }
 

 

 

See more website here...

  • Odlinks
  • Farsi-News
  • Advertise Here