Blog

SERIAL MONITOR TO LCD DISPLAY

LCD serial

/*In this project, we demonstrate the sending of characters from the serial monitor to the LCD display.

The code can be downloaded at :

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Serial_to_LCD.zip

*/

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);
LCD *myLCD = &lcd;

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}

void loop() {
// when characters arrive over the serial port…
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}

CONTROLLING SERVO VIA SERIAL MONITOR

servo serial

/* We can control this servo through
the serial monitor,
type the angle value that we want (0-180)
then press enter.

the code can be downloaded at :

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Servo_serial.zip

*/

#include <Servo.h>

Servo servo1;
long num;

void setup()
{
servo1.attach(9);
Serial.begin(9600);
Serial.print(“Enter Position = “);
}

void loop()
{
while(Serial.available()>0)
{
num= Serial.parseInt();
Serial.print(num);
Serial.println(” degree”);
Serial.print(“Enter Position = “);
}
servo1.write(num);
delay(15);
}

CONTROL STEPPER IR REMOTE

STepper remote

The code can be downloaded at :

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Stepper_remote.zip

#include “Stepper.h”
#include “IRremote.h”
#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
int receiver = 3; // Signal Pin of IR receiver to Arduino Digital Pin 6

// In1, In2, In3, In4 in the sequence 1-3-2-4
Stepper small_stepper(STEPS, 12, 10, 11, 9);
IRrecv irrecv(receiver); // create instance of ‘irrecv’
decode_results results; // create instance of ‘decode_results’
void setup()
{
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?

{
switch(results.value)
{
case 0x20F0E01F: // RIGHT button pressed
small_stepper.setSpeed(500); //Max seems to be 700
Steps2Take = 2048; // Rotate CW 360 deg
small_stepper.step(Steps2Take);
break;

case 0x20F0609F: // LEFT button pressed
small_stepper.setSpeed(500);
Steps2Take = -1024; // Rotate CCW 180 deg
small_stepper.step(Steps2Take);
break;
}
irrecv.resume(); // receive the next value
}
}

LIGHTNING COUNTER WITH LED DISPLAY(COMMON ANODE)

lightning conter

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Lightning_counter_with_display.zip

const int buttonPin = 2;
int digit1 = 11; //PWM Display pin 1
int digit2 = 10; //PWM Display pin 2
int digit3 = 9; //PWM Display pin 6
int digit4 = 6; //PWM Display pin 8

int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button

//Pin mapping from Arduino to the ATmega DIP28 if you need it
//http://www.arduino.cc/en/Hacking/PinMapping
int segA = A1; //Display pin 14
int segB = 3; //Display pin 16
int segC = 4; //Display pin 13
int segD = 5; //Display pin 3
int segE = A0; //Display pin 5
int segF = 7; //Display pin 11
int segG = 8; //Display pin 15

void setup() {
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);

pinMode(digit1, OUTPUT);
pinMode(digit2, OUTPUT);
pinMode(digit3, OUTPUT);
pinMode(digit4, OUTPUT);

pinMode(13, OUTPUT);

// initialize the button pin as a input:
pinMode(buttonPin, INPUT);

// initialize serial communication:
Serial.begin(9600);
}

void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);

// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == LOW) {

buttonPushCounter++;
//Serial.println(“on”);
Serial.print(“number of lightning: “);
Serial.println(buttonPushCounter);
} else {

}
// Delay a little bit to avoid bouncing
delay(1);
}

lastButtonState = buttonState;

displayNumber(buttonPushCounter);

}

void displayNumber(int toDisplay) {
#define DISPLAY_BRIGHTNESS 1000

#define DIGIT_ON HIGH
#define DIGIT_OFF LOW

long beginTime = millis();

for(int digit = 4 ; digit > 0 ; digit–) {

//Turn on a digit for a short amount of time
switch(digit) {
case 1:
digitalWrite(digit1, DIGIT_OFF);
break;
case 2:
digitalWrite(digit2, DIGIT_OFF);
break;
case 3:
digitalWrite(digit3, DIGIT_OFF);
break;
case 4:
digitalWrite(digit4, DIGIT_OFF);
break;
}

//Turn on the right segments for this digit
lightNumber(toDisplay % 10);
toDisplay /= 10;

delayMicroseconds(DISPLAY_BRIGHTNESS);
//Display digit for fraction of a second (1us to 5000us, 500 is pretty good)

//Turn off all segments
lightNumber(10);

//Turn off all digits
digitalWrite(digit1, DIGIT_ON);
digitalWrite(digit2, DIGIT_ON);
digitalWrite(digit3, DIGIT_ON);
digitalWrite(digit4, DIGIT_ON);
}

while( (millis() – beginTime) < 10) ;
//Wait for 20ms to pass before we paint the display again
}

//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {

#define SEGMENT_ON LOW
#define SEGMENT_OFF HIGH

switch (numberToDisplay){

case 0:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_OFF);
break;

case 1:
digitalWrite(segA, SEGMENT_OFF);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_OFF);
break;

case 2:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_OFF);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_ON);
break;

case 3:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_ON);
break;

case 4:
digitalWrite(segA, SEGMENT_OFF);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;

case 5:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_OFF);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;

case 6:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_OFF);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;

case 7:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_OFF);
break;

case 8:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;

case 9:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;

case 10:
digitalWrite(segA, SEGMENT_OFF);
digitalWrite(segB, SEGMENT_OFF);
digitalWrite(segC, SEGMENT_OFF);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_OFF);
break;
}
}

LED WITH MULTIPLEXER 74HC4067

LED 74HC4067

The code can be downloaded at :

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/74HC4067_LED.zip

#include <Mux.h>

Mux mux(2,3,4,5,6); // initialise on construct…
int counter=0;

void setup(){
Serial.begin(9600);
mux.setup(8,9,10,11,4); // initialise Mux (s0,s1,s2,s3,sig)
}

void loop(){
mux.write(0, HIGH); //Turn ON the selected LED
delay(100);
mux.write(0, LOW); //Turn OFF the selected LED
mux.write(1, HIGH); //Turn ON the selected LED
delay(100);
mux.write(1, LOW); //Turn OFF the selected LED
mux.write(2, HIGH); //Turn ON the selected LED
delay(100);
mux.write(2, LOW); //Turn OFF the selected LED
mux.write(3, HIGH); //Turn ON the selected LED
delay(100);
mux.write(3, LOW); //Turn OFF the selected LED
mux.write(4, HIGH); //Turn ON the selected LED
delay(100);
mux.write(4, LOW); //Turn OFF the selected LED
mux.write(5, HIGH); //Turn ON the selected LED
delay(100);
mux.write(5, LOW); //Turn OFF the selected LED
mux.write(6, HIGH); //Turn ON the selected LED
delay(100);
mux.write(6, LOW); //Turn OFF the selected LED
mux.write(7, HIGH); //Turn ON the selected LED
delay(100);
mux.write(7, LOW); //Turn OFF the selected LED
mux.write(8, HIGH); //Turn ON the selected LED
delay(100);
mux.write(8, LOW); //Turn OFF the selected LED
mux.write(9, HIGH); //Turn ON the selected LED
delay(100);
mux.write(9, LOW); //Turn OFF the selected LED
mux.write(10, HIGH); //Turn ON the selected LED
delay(100);
mux.write(10, LOW); //Turn OFF the selected LED
mux.write(11, HIGH); //Turn ON the selected LED
delay(100);
mux.write(11, LOW); //Turn OFF the selected LED
mux.write(12, HIGH); //Turn ON the selected LED
delay(100);
mux.write(12, LOW); //Turn OFF the selected LED
mux.write(13, HIGH); //Turn ON the selected LED
delay(100);
mux.write(13, LOW); //Turn OFF the selected LED
mux.write(14, HIGH); //Turn ON the selected LED
delay(100);
mux.write(14, LOW); //Turn OFF the selected LED
mux.write(15, HIGH); //Turn ON the selected LED
delay(100);
mux.write(15, LOW); //Turn OFF the selected LED

}

++++OTHER SKET++++++

#include <Mux.h>

Mux mux(2,3,4,5,4); // initialise on construct…
int counter=0;

void setup(){
Serial.begin(9600);
mux.setup(8,9,10,11,4); // initialise Mux (s0,s1,s2,s3,sig)
}

void loop(){
mux.write(counter, HIGH); //Turn ON the selected LED
delay(500);
mux.write(counter, LOW); //Turn OFF the selected LED

if(counter==15){
Serial.println(counter); //Print results
}
else{
Serial.print(counter);
Serial.print(“, “);
}

counter = ++counter & 15; //Add +1 to counter until 15
}