Skip to main content

LED on Switch using Arduino Nano


A lot of things as newbie to do with Arduino. Today,  we will do a simple circuit using Arduino.

Let try..



Code :

// set pin numbers:
const int buttonPin = 3;     // the number of the push button pin
const int ledPin =  11;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the push button status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }

}


Comments

Popular posts from this blog

Arduino Interfacing With LCD(16x02) Without Potentiometer

All, today i gonna to share how Arduino connected to LCD(16x02). LCD 16x02 means 16 character in 2 rows. Connection between LCD and UNO Code: #include <LiquidCrystal.h> int Contrast=75;  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);   void setup()  {     analogWrite(6,Contrast);      lcd.begin(16, 2);   }      void loop()  {      lcd.setCursor(0, 0);      lcd.print("ITS WORK");        lcd.setCursor(0, 1);      lcd.print("WELL DONE");  }

L298N motor with Ultrasonic Sensor using Can Bus MCP2515

Today, I will share the project where we use 2x Arduino where each Arduino act as Transmitter to measure a distance using Ultrasonic sensor and Receiver controlling L98N motor driver. Ultrasonic Sesnor L298N Motor Driver            Two output Motor Driver with Enable pin for both Motor. Requirement: 1. 2x Arduino 2. 2x MCP2515 CAN module 3. L298N Motor Driver 4. Ultrasonic Sensor 5. 12V battery 6. Download NewPing, SPI and mcp2515 into Arduino. Instruction: 1. Connect Arduino Nano to Ultrasonic sensor. 2. Connect Arduino Nano to MCP2515(1) through SPI connection. 3. Connect MCP2515(1) with MCP2515(2) using CAN-H and CAN-L wire. 4. Connect MCP2515(2) to Arduino Uno through SPI connection. 5. Connect Arduino Uno with Motor L298N. Code: Transmitter: #include <NewPing.h> #include <SPI.h>          //Library for using SPI Communication ...

Ultrasonic Sensor With Arduino Uno

Yeah, Ultrasonic sensor now its working. Today i am gonna to share the code of how its work:) It quite easy. We just need to connect 4-pin which is VCC,GND,ECHO and TRG from Ultrasonic sensor to Arduino. Done:) Code : int trigger_pin = 4; int echo_pin = 2; int LED_pin = 13; int time; int distance; void setup ( ) {         Serial.begin (9600);         pinMode (trigger_pin, OUTPUT);         pinMode (echo_pin, INPUT);         pinMode (LED_pin, OUTPUT); } void loop ( ) {     digitalWrite (trigger_pin, HIGH);     delayMicroseconds (10);     digitalWrite (trigger_pin, LOW);     time = pulseIn (echo_pin, HIGH);     distance = (time * 0.034) / 2;   if (distance <= 10)         {  ...