// the setup function runs once when you press reset or power the boardvoidsetup() {// initialize digital pin LED_BUILTIN as an output.pinMode(LED_BUILTIN, OUTPUT);}// the loop function runs over and over again forevervoidloop() {digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)delay(1000); // wait for a seconddigitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOWdelay(1000); // wait for a second}
// constants won't change. Used here to set a pin number:constint ledPin = LED_BUILTIN;// the number of the LED pin// Variables will change:int ledState = LOW; // ledState used to set the LED// Generally, you should use "unsigned long" for variables that hold time// The value will quickly become too large for an int to storeunsignedlong previousMillis =0; // will store last time LED was updated// constants won't change:constlong interval =1000; // interval at which to blink (milliseconds)voidsetup() {// set the digital pin as output:pinMode(ledPin, OUTPUT);}voidloop() {// here is where you'd put code that needs to be running all the time.// check to see if it's time to blink the LED; that is, if the difference// between the current time and last time you blinked the LED is bigger than// the interval at which you want to blink the LED.unsignedlong currentMillis =millis();if (currentMillis - previousMillis >= interval) {// save the last time you blinked the LED previousMillis = currentMillis;// if the LED is off turn it on and vice-versa:if (ledState == LOW) { ledState = HIGH; } else { ledState = LOW; }// set the LED with the ledState of the variable:digitalWrite(ledPin, ledState); }}
// digital pin 2 has a pushbutton attached to it. Give it a name:int pushButton =2;// the setup routine runs once when you press reset:voidsetup() {// initialize serial communication at 9600 bits per second:Serial.begin(9600);// make the pushbutton's pin an input:pinMode(pushButton, INPUT);}// the loop routine runs over and over again forever:voidloop() {// read the input pin:int buttonState =digitalRead(pushButton);// print out the state of the button:Serial.println(buttonState);delay(1); // delay in between reads for stability}
We can combine with First program and pushbutton
// digital pin 2 has a pushbutton attached to it. Give it a name:int pushButton =2;constint ledPin = LED_BUILTIN;int ledState = LOW; unsignedlong previousMillis =0; constlong interval =1000;// the setup routine runs once when you press reset:voidsetup() {// initialize serial communication at 9600 bits per second:Serial.begin(9600);// make the pushbutton's pin an input:pinMode(pushButton, INPUT);pinMode(ledPin, OUTPUT);}// the loop routine runs over and over again forever:voidloop() {unsignedlong currentMillis =millis();// read the input pin:int buttonState =digitalRead(pushButton);// print out the state of the button:Serial.println(buttonState);delay(1); // delay in between reads for stabilityif (currentMillis - previousMillis >= interval) {// save the last time you blinked the LED previousMillis = currentMillis;// if the LED is off turn it on and vice-versa:if (ledState == LOW) { ledState = HIGH; } else { ledState = LOW; }// set the LED with the ledState of the variable:digitalWrite(ledPin, ledState); }}
!! Connect TX Arduino to RX GPS -> don't make mistake
Open on the right top corder of Arduino App the Serial display
Get the NEMA Format GPS
/* * MARC-ANTOINE LEMAIRE - GPS Raw Data: NMEA Sentences */#include<SoftwareSerial.h>// The serial connection to the GPS moduleSoftwareSerial ss(4,3);voidsetup(){Serial.begin(9600);ss.begin(9600);}voidloop(){while (ss.available() >0){// get the byte data from the GPS byte gpsData =ss.read();Serial.write(gpsData); }}// Output interesting:// $GNGGA,162839.000,5037.76633,N,00449.22393,E,1,11,0.9,148.3,M,45.9,M,,*4C// GGNA, Time, Lat, N, Long, E, 1=Fix Quality, NumSatellite, Dilluation, altitude,
/* * MARC-ANTOINE LEMAIRE */#include<TinyGPS++.h>#include<SoftwareSerial.h>staticconstint RXPin =4, TXPin =3;// Connect TXPin3 Arduino to RX GPS// Connect RXPin4 Arduino to TX GPSstaticconstuint32_t GPSBaud =9600;// The TinyGPS++ objectTinyGPSPlus gps;// The serial connection to the GPS deviceSoftwareSerial ss(RXPin, TXPin);voidsetup(){Serial.begin(9600);ss.begin(GPSBaud);}voidloop(){// This sketch displays information every time a new sentence is correctly encoded.while (ss.available() >0){gps.encode(ss.read());if (gps.location.isUpdated()){Serial.print("Latitude= "); Serial.print(gps.location.lat(),6);Serial.print(" Longitude= "); Serial.print(gps.location.lng(),6);// Altitude in meters (double)Serial.print(" Altitude in meters = "); Serial.print(gps.altitude.meters()); // Number of satellites in use (u32)Serial.print(" Number of satellites in use = "); Serial.print(gps.satellites.value()); // Raw time in HHMMSSCC format (u32)Serial.print(" Raw time in HHMMSSCC = "); Serial.println(gps.time.value()); delay(5000);// We display all the 5 sec the position. } }}