So right now i'm making a smart trashcan; the trashcan consists of 2 ultrasonic sensor, 1 servo SG90, 1 RFID and, 1 RGB led light. other than that the arduino is powered by a 3.7 V battery that is solar powered.
here are some of the images and schematics.
here is the code I use.
[code]#include <Servo.h> //
#include <SPI.h> //
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
#define trigpins 2
#define echopins 3
#define LEDPin 13
int trigPin = 4;
int echoPin = 5;
long distance;
long duration;
int redpin = 7;
int greenpin = 8;
int bluepin = 9;
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
Servo lover;
int maximumRange = 200;
int minimumRange = 0;
long durationl, distancel;
//5V
void setup() {
lover.attach(6);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigpins, OUTPUT); //set trigpin as output
pinMode(echopins, INPUT); //set echopin as input
pinMode(redpin, OUTPUT); // set R,G and B as outputs
pinMode(greenpin, OUTPUT);
pinMode(bluepin, OUTPUT);
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
digitalWrite(trigpins, LOW);
delayMicroseconds(2);
digitalWrite(trigpins, HIGH);
delayMicroseconds(10);
digitalWrite(trigpins, LOW);
durationl = pulseIn(echopins, HIGH);
distancel = durationl/58.2;
if(distancel >= 1 && distancel <= 5){
setColor(230, 0, 0); // red
delay(100);
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
if (mfrc522.uid.uidByte[0] == 0xD2 && mfrc522.uid.uidByte[1] == 0xD9 && mfrc522.uid.uidByte[2] == 0x79 && mfrc522.uid.uidByte[3] == 0x0E) //dumpinfo chane this part
{
lover.write( -90 );
delay(10000);
lover.write( 90 );
}
}
else if (distancel >=6 && distancel <= 23){
setColor(230, 0, 25); // purple
delay(100);
ultra();
if(distance <= 15){
lover.write(-90);
delay(5000);
lover.write(90);
}
}
else if (distancel >= 24){
setColor(0, 0, 230); // blue
delay(100);
ultra();
if(distance <= 15){
lover.write(-90);
delay(5000);
lover.write(90);
}
}
}
void setColor(int red, int green, int blue)
{
analogWrite(redpin, red);
analogWrite(greenpin, green);
analogWrite(bluepin, blue);
}
void ultra()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
}
[/code]
The problem is I have 3 separated programs one is Ultrasonic(1 at the lid) and the RGB led running at the same time.
Second is Ultrasonic at front and the servo, then the last is the RFID and the servo.
I tried using a 9V battery to run the sensors separately from the UNO but it isn't working
I hope you guys can help me out
I hope that I can power this trashcan using solar power but its kind of hard.







