Hardware required
1. Arduino UNO - 2pcs.2. Nokia 5110 LCD display - 1pcs.
3. LDR - 1pcs.
4. Resistor 10 Kohm - 6pcs.
5. Resistor 1 Kohm -1 pcs.
6 Jumper wires - 15 pcs.
7.Breadboard -1pcs.
Project description
In this project, I am going to make one Light meter by using light depended resistor (LDR) and showing Arduino to Arduino I2C communication through wire library. For light measurement display, I am using Nokia 5110 LCD display and library is using for that one is pcd8544 library, you can download it from internet by searching in google.
Connection Diagram
Program
1. Program for Master Arduino.
// Wire Master Writer
#include <Wire.h>
float light;
int x;
void setup()
{
Wire.begin();
Serial.begin(9600);
// join i2c bus (address optional for master)
}
void loop()
{
// connect LDR to analog A0 input by using 10 k ohm resistance as pull up resistor as shown in
// connection digram.
// connect LDR to analog A0 input by using 10 k ohm resistance as pull up resistor as shown in
// connection digram.
light=analogRead(A0);
x=map(light,0,1024,0,255);
Serial.println(x);
Wire.beginTransmission(8); // transmit to device #8
Wire.write("light intensity"); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
delay(500);
}
2. Program for Slave Arduino.
// Wire Slave Receiver
#include <Wire.h>
// Using wire library it is inbuilt in arduino IDE
#include <PCD8544.h>
// Library for nokia 5110 display. download it from internet
// Nokia 5110 lcd connection
// Nokia 5110 lcd is working wit 3.3 VDC so need to reduce +5v of arduino to 3.3V
// connect 10 k ohm resistance with every connection except vcc, Gnd and BL
// RST connect to 10 k-Ohm resistance series and pin no 6 of Arduino
// CE connect to 10 k-Ohm resistance series and pin no 7 of Arduino
// DC connect to 10 k-Ohm resistance series and pin no 5 of arduino
// Din connect to 10 k-Ohm resistance series and pin no 4 of arduino
// Clk connect to 10 k-Ohm resistance series and pin no 3 of arduino
// Vcc to +5v of arduino directly
// BL connect with 1k ohm to arduino pin +5v
// Gnd to Gnd of arduino
static const byte glyph[] = { B00010000, B00110100, B00110000, B00110100, B00010000 };
int x;
static PCD8544 lcd;
void setup()
{
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
lcd.begin(84, 48);
}
void loop()
{
delay(100);
lcd.setCursor(0, 0);
lcd.print("Light in % ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,2);
lcd.print(" "+String(x)+"%");
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while (1 < Wire.available())
{
// loop through all but the last
char c = Wire.read(); // receive byte as a character
}
x = Wire.read(); // receive byte as an integer
x=map(x,0,255,0,100); //mapping for getting percentage
}
No comments:
Post a Comment