Hello, Arduino community,
I would love your guidance on an issue I have for a school project.
I am trying to make a system that, when one hand is removed from a steering wheel, an engine (3D printed and powered by a DC motor) will slow down, and a green light strip (LED strip) will cycle through each pixel. In addition, an LCD screen will display this drop in speed as a percentage.
For components, I am using:
Arduino Uno R3
2 Force Sensitive Resistors
DC Motor
Resistors (220 and 10k ohm)
LED strip (4 pixels)
LCD Display (16x2)
9V battery
I can get the LCD and FSR's to work fine, however, the motor isn't spinning fast enough to rotate the engine. It doesn't create enough power to rotate enough. And the LED strip doesn't even turn on when plugged into the system.
Here is my wiring (I switched to an I2C LCD display, but the rest is the exact same):
And here is my code:
// include the library code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// include neopixel library
#include <Adafruit_NeoPixel.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
int pressurePin1 = A0;
int forceA;
int pressurePin2 = A1;
int forceB;
int DCMotor = 9;
//Led Strip constraints
const int dinPin = 6; // Din pin to Arduino pin 6
const int numOfLeds = 4; // Number of leds
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(numOfLeds, dinPin, NEO_GRB + NEO_KHZ800);
// Colour LED pixels
int red = 0; //Value from 0(led-off) to 255().
int green = 255;
int blue = 0;
void setup() {
Serial.begin (9600);
pinMode (DCMotor, OUTPUT);
pixels.begin(); // Initializes the NeoPixel library
pixels.setBrightness(100); // Value from 0 to 100%
// set up the LCD's number of columns and rows:
lcd.begin();
// Print a message to the LCD.
lcd.print ("Initialising...");
delay (1000);
lcd.clear ();
delay (1000);
lcd.print(" Safety Wheel ");
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print (" Arya Nayak ");
delay (5000);
lcd.clear ();
lcd.print (" Engine Speed");
lcd.setCursor(0, 1);
lcd.print ("100%");
analogWrite (DCMotor, 255);
}
void loop (){
forceA = analogRead(pressurePin1);
forceB = analogRead(pressurePin2);
Serial.println(forceA);
Serial.println(forceB);
if(forceA < 500){
lcd.clear ();
lcd.print (" Engine Speed");
lcd.setCursor (0,1);
lcd.print ("50%");
analogWrite (DCMotor, 128);
for(int i=0;i<numOfLeds;i++){
pixels.setPixelColor(i, pixels.Color(red,green,blue));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(200); // Delay for a period of time to change the next led
pixels.clear ();
delay (200);
delay (100);
}
}
else if (forceB < 500){
lcd.clear ();
lcd.print (" Engine Speed");
lcd.setCursor (0,1);
lcd.print ("50%");
analogWrite (DCMotor, 128);
for(int i=0;i<numOfLeds;i++){
pixels.setPixelColor(i, pixels.Color(red,green,blue));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(200); // Delay for a period of time to change the next led
pixels.clear ();
delay (200);
delay (100);
}
}
else {
analogWrite (DCMotor, 255);
lcd.clear ();
lcd.print (" Engine Speed");
lcd.setCursor (0,1);
lcd.print ("100%");
for(int i=0;i<numOfLeds;i++){
pixels.clear ();
delay (200);
}
}
delay (4500) ;
}
Would deeply appreciate any recommendations from you guys.
Thank you so much (and sorry for the lengthy post).