HOW I MADE MY FIRST PROJECT IN ARDUINO MEGA 2560

nwoga kizito
3 min readApr 11, 2022

how are you guys doing, hope you guys are doing well, because this article going to make your day. why? this video is not me explaining a topic or a product, but this time I am sharing my experience on how I made my first Arduino mega2560. what is Arduino mega 2560? This is type or model of an Arduino, example : Arduino Uno, Arduino Nano E.T.C.

so what exactly was my first project, was it an iron man suit or jet pack. its none of the above, but my first project was smart trash can.

Not what you expect, but not bad as my first project with Arduino mega 2560. so going to explain how I made a smart trash can, but first Arduino mega 2560 has different features than Arduino Uno and Arduino Nano and the rest so the code is different from the rest and also the pin mode, what is pin mode? pin mode is the pot in an Arduino where the wire goes in. so how does an Arduino Uno, Arduino mega 2560 and the rest look like.

so what are some of there function of Arduino and component

Arduino Uno16Mhz ATmega3282KB SRAM, 32KB flash146 input, 0 output, Arduino Due84MHz AT91SAM3X8E96KB SRAM, 512KB flash5412 input, 2 output, Arduino Mega16MHz ATmega25608KB SRAM, 256KB flash5416 input, 0 output, Arduino Leonardo16MHz ATmega32u42.5KB SRAM, 32KB flash2012 input, 0 output

Above is some of the component and function, let get start the project.

STEP ON HOW TO MAKE A SMART TRASH CAN :

  1. first get your bucket, then glue the handle to the end of the bucket.
  2. then you put your servo motor that moves 180 degree.
  3. then you put your servo motor in it pin mode.
  4. the make two holes in the middle, then you put your ultrasonic sensor
  5. then you put ultrasonic sensor in its pin mode.
  6. then put the code on the Arduino mega 2560.

so guy it might seem boring, but it is very interesting. if you what to get the code I wrote down.

#include <Servo.h>   //servo library
Servo servo;
int trigPin = 5;
int echoPin = 6;
int servoPin = 7;
int led= 10;
long duration, dist, average;
long aver[3]; //array for average


void setup() {
Serial.begin(9600);
servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.write(0); //close cap on power on
delay(100);
servo.detach();
}

void measure() {
digitalWrite(10,HIGH);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1; //obtain distance
}
void loop() {
for (int i=0;i<=2;i++) { //average distance
measure();
aver[i]=dist;
delay(10); //delay between measurements
}
dist=(aver[0]+aver[1]+aver[2])/3;

if ( dist<50 ) {
//Change distance as per your need
servo.attach(servoPin);
delay(1);
servo.write(0);
delay(3000);
servo.write(150);
delay(1000);
servo.detach();
}
Serial.print(dist);
}

so guy if you do not understand I will leave a link to a video, cheers guys for now.https://www.youtube.com/watch?v=9yrP1CZN3Ds&t=39s.

--

--