0

I'm trying to make a speedometer that will change colors depending on the speed on which I am traveling.

If the speed is decreasing at any time or below 5 mph LEDs be red.

And if the speed is above 5 mph or increasing speed the LEDs will be a different color.

I am using an Adafruit 24 NeoPixel ring for LED's and a u-blox NEO-6 GPS module.

And the GPS is sometimes not registering the speed or any other GPS values and not switching colors when speed is at certain values or when it is increasing or decreasing. It tends to stay only one color no matter the speed. Also the GPS is not registering speeds above zero when I ride my bike or in a moving car.

I added a picture of the values I am getting, it seems to be connecting to satellites and getting correct GPS coordinates but as soon as I as I take it to real world test, the speed inst changing and LEDs are not changing. I also included a picture of the Arduino configuration I am using.

I am a very new to coding so any help would be very grateful.

(if anyone could help with the accelerating and decelerating code to that would be absolutely amazing!!!!)

enter image description here


#include "TinyGPS++.h"
#include "SoftwareSerial.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define LED_PIN  6
#define LED_COUNT 24
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);
SoftwareSerial serial_connection(10,11);
int speedM;
TinyGPSPlus gps;

void setup() {
  #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  strip.begin();
  strip.show();
  strip.begin();
  Serial.begin(9600);
  serial_connection.begin(9600);
  Serial.println("Project Red Stop");
}
void loop() {
speedM = gps.speed.mph();
//int val = speedM;
 while(serial_connection.available())//While there are characters to come from the GPS
  {
    gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time
  }
  if(speedM < 5)
  //   if(speedM < 5 & val--)
  {
    Serial.println("Speed MPH:");
    Serial.println(gps.speed.mph());
    Serial.println("Satellite Count:");
    Serial.println(gps.satellites.value());
    Serial.println("Latitude:");
    Serial.println(gps.location.lat(), 6);
    Serial.println("Longitude:");
    Serial.println(gps.location.lng(), 6);
    colorWipe(strip.Color(0,100,0), 100);                
   // strip.setPixelColor(0, strip.Color(0,100,0));                   // gps works faster with this: 
    strip.show();
    delay(10);
  }
  else if(speedM > 5) 
  //   else if(speedM > 5 & val++) 
  {
    Serial.println("Speed MPH:");
    Serial.println(gps.speed.mph()); 
    Serial.println("Satellite Count:");
    Serial.println(gps.satellites.value());
    Serial.println("Latitude:");
    Serial.println(gps.location.lat(), 6);
    Serial.println("Longitude:");
    Serial.println(gps.location.lng(), 6); 
    colorWipe(strip.Color(0,100,100), 100);
    strip.show();
    delay(10);
  }
}
void colorWipe(uint32_t color, int quick) {
  for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
    strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    strip.show();                          //  Update strip to match
    delay(0);                           //  Pause for a moment
  }
}

enter image description here

  • why do you expect the color of the LEDs to change if you cannot determine the speed? – jsotola Nov 7 '19 at 16:14
  • I am just looking for help. You are right if i cant get speed i cant get color change. but i figured i just ask for help. – flowerspowers Nov 7 '19 at 16:35
  • Separate your code into two parts: measuring speed with the GPS, and displaying LED colors according to acceleration & velocity (which you would provde as constants or terminal inputs). Get each part working, then recombine them. It's much easier to build up your application piece by piece, substituting trivial code - called 'stubs' - for the parts that don't exist yet, than it is to write the whole app and then try to debug everything at once. The stubs just provide made-up data instead of trying to get it from a complex devices like a GPS. – JRobert Nov 7 '19 at 16:44
  • 1
    Why didn't you edit your first question. It is the same. You should delete one of them – chrisl Nov 7 '19 at 17:18
  • Im very new to this site, i did not know i could edit previous posts, thank you for that fact ill try to remove the older post. – flowerspowers Nov 7 '19 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.