I need help for writing a c code for a program.

Hi,
I need a C code for this idea.

project.PNG

project.PNG

why do I think this is straight out of a homework assignment?

I've deleted your other cross-post @sadiqmizel.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

@sadiqmizel - Report to moderator was not the correct way to reply to the topic

No, it's for a project.

you might want to say it different. But your headline and the posting in my ears sounds like
if you would say.

"I don't want to learn programming - just post the code that does function like described AND HURRY UP WITH FINISHING IT!!"

I apologise if I'm misinterpreting your posting. At least i could be misunderstood like that.

So to maximise your chances to get support here in the forum is to:

  • avoid writing a headline completely in capital letters. It is considered as shouting.
  • choose a headline that gets to the point what your question is
  • showing at least some own effort in trying to begin writing code.

Everybody here in this forum is free to answer or not.

It might be that you were really upset while writing this posting. And you put all your angryness into the posting.
Can happen. Anyway you should try to calm down and after calming down writing a neutral sounding posting.

So if you are a real beginner. At any point in moving towards finishing your project there arises a question. It really dosn't matter what the question is. It could be even "which program do I need to program an arduino?"

So whatever your first real question is - just re-edit the titel of your first posting and write the question.

There are a lot of people here that enjoy answering concrete questions if they can see a progress in learning by the person who asked the question. And like always and everywhere everybody enjoys reading a "thank you"

best regards Stefan

What have you tried, so far?

Which Arduino? Which LCD? Which LED? What servo? What power supply for the servo?

Can you post a schematic?

HI sadigmizel,
congrats for re-editing the headline. Still your initial post is a bit short.

The microcontroller-world isn't superstandardized like USB-devices.
You have to take care of a bit more details than just "does the plug fit into the socket?"

This is the reason why you are asked

What have you tried, so far?
Which Arduino? Which LCD? Which LED? What servo? What power supply for the servo?
Can you post a schematic?

So you might have to make a fundamental decision:

Do you want to invest several hours of learning - go on with answering the questions you have been asked
or with a more detailed description of your project

If you don't want to invest several hours: abandon the project.

I invite you to decide for learning. You will have a lot of fun making a microcontroller doing the things you want it to.
best regards Stefan

groundFungus:
What have you tried, so far?

Which Arduino? Which LCD? Which LED? What servo? What power supply for the servo?

Can you post a schematic?

This code what i tried to complete it and on the attachments pic for the circuit.
Hint: It's virtual.

//include the library code:
#include <LiquidCrystal.h>
#include <Servo.h>

//SERVO
// Declare the Servo pin
int servoPin = 13;
// Create a servo object
Servo Servo1;

// LCD ////////////////
const int buttonPin1 = 14;
const int buttonPin2 = 15;
const int rs = 5, en = 4, d4 = 3, d5 = 2, d6 = 1, d7 = 0;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

//Buttons ////////////
int buttonState1 = 0; // current state of button 1
int buttonState2 = 0; // current state of button 2
int lastButtonState = 0; // previous state of the button
/////////////////////
//

//Keypad ////////////
char keys [4] [3] = {
{'1','2','3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*','0','#'}
};

uint8_t row = 0; //row index
uint8_t col = 0; //column index const
const uint8_t no_rows=4; //number of rows in the keypad
const uint8_t no_cols=3; //number of columns in the keypad

uint8_t rowPins [no_rows] = {6,7,8,9}; //connect to the row pinouts of the keypad
uint8_t colPins [no_cols] = {12,11,10}; //connect to the column pinouts of the keypad

//Counters & arrays //////////
int counter = 6; // button counter
int maxDigits=4; //accept only 4 digits
int maxDigits2=4;
int selectOption=0; //option through LCD
int takeCounter; //Indicate the stage on EEPROM array

int selectedEnterKeys[4] = {0,0,0,0}; //intialize
int selectedResetKeys[4] = {0,0,0,0}; //intialize
////////////////////////////
//

void setup() {
Serial.begin(9600);

//SERVO
Servo1.attach(servoPin);

//LCD
pinMode(buttonPin1, INPUT);

pinMode(buttonPin2, INPUT);

lcd.begin(16,2);

lcd.setCursor(7,1);

//Keypad
for (int i=0; i<no_rows; i++){
pinMode(rowPins*,OUTPUT);*

  • }*
  • for(int i=0; i<no_cols; i++){*
    pinMode(colPins*,INPUT_PULLUP);
    _
    }*_

* //LED*
* pinMode(11, OUTPUT);*

}
void loop() {
* //Servo*
* // Make servo go to 0 degrees*
* Servo1.write(0);*
* delay(1000);*
* // Make servo go to 90 degrees*
* Servo1.write(90);*
* delay(1000);*
* //Buttons + LCD*
* //button 1 (next) *
* buttonState1 = digitalRead(buttonPin1);*
* if(selectOption==0){*
* lcd.setCursor(6,0);*
* lcd.print("-WELCOME !");*
* }*

* if (buttonState1 != lastButtonState) {*

* if (buttonState1 == HIGH) {*
* selectOption++;*
* if(selectOption==3){*
* lcd.clear();*
* selectOption=0; *
* }*

* }*
* lcd.clear();*

* delay(100);*
* }// end of button 1*

* lastButtonState = buttonState1;*
* //button 2 (back)*
* buttonState2 = digitalRead(buttonPin2);*
* if (buttonState2 != lastButtonState) {*

* if (buttonState2 == HIGH){*

* selectOption--;*
* if(selectOption==-3){*
* lcd.clear();*
* selectOption=0; *
* }*
* }*
* lcd.clear();*
* delay(100); *

* }// end of button 2*
* lastButtonState = buttonState2;*
* //Keypad*
* bool key_pressed=false;
key_pressed=get_key();
if(key_pressed == true || buttonState1 == HIGH || buttonState2 == HIGH ){
_
digitalWrite(8, HIGH); _
_
delay(1000); _
_
}*_

}//end of loop()
//keypad keys return
bool get_key(void){
uint8_t x=0;
int tryLimit=1; //ONE try is allowed
}


StefanL38:
HI sadigmizel,
congrats for re-editing the headline. Still your initial post is a bit short.

The microcontroller-world isn't superstandardized like USB-devices.
You have to take care of a bit more details than just "does the plug fit into the socket?"

This is the reason why you are asked So you might have to make a fundamental decision:

Do you want to invest several hours of learning - go on with answering the questions you have been asked
or with a more detailed description of your project

If you don't want to invest several hours: abandon the project.

I invite you to decide for learning. You will have a lot of fun making a microcontroller doing the things you want it to.
best regards Stefan

Hi,
First of all, thank you for your instructions and sorry about what happend because this is my first time to use this website.
I've upload my code + my circuit you can see it now.
Regards,
Sadiq

wow pretty long code and beautiful schematic.
Still some things to learn how to use the forum.

it makes sense to have some empty lines to group the code but not too much of them.
You should delete the too much empty lines of code.

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy to forum"

re-edit your posting with the code.
Delete the code and then
3) paste clipboard into write-window of a posting

best regards Stefan

Does your code compile? If yes give a description of what behaviour you see and how this deviates from what you want
best regards Stefan

const int rs = 5, en = 4, d4 = 3, d5 = 2, d6 = 1, d7 = 0;

Do not use D0 or D1.

These pins are meant for Serial communications, you can use A3(D17) and A4(D18) instead.


Powering a Servo from the Arduino 5v pin is never recommended.

This can cause noise on the power line and/or damage the Arduino.

Use a separate power supply, try four 1.5 volt batteries (total of 6v); make sure battery 0v goes to the Arduino GND.


Never connect a digital input (D14 D15) to Vin !

You will blow your Arduino, POOF !


It appears you ‘are not’ connecting some necessary pins on the LCD, review its connections.


        key_pressed=get_key();
         if(key_pressed == true || buttonState1 == HIGH || buttonState2 == HIGH ){
        digitalWrite(8, HIGH);   
         delay(1000);

digitalWrite(8, HIGH); // Why ?


Correct aforementioned items before progressing and repost things.

That is no way to connect buttons (normally open momentary switches). The best way is to wire one side of the switch to ground and the other side to an input set to pinMode INPUT_PULLUP. The input will read HIGH when the switch is open (not pressed) and LOW when closed (pressed). The wiring on the right is for the ubiquitous 4 terminal 6mm tactile switches. The analog inputs are fine to use as digital inputs for switches.

The LCD is missing a resistor for the contrast setting. I usually start with a 1K fixed resistor from the contrast pin (LCD pin 3) to ground. There may be an advantage to using a pot versus a fixed resistor. If the supply voltage can vary then the contrast may need to be adjusted. The correct way to wire a pot is to wire one end of the pot to ground and the wiper to pin 3. The other end of the pot not connected or connected to the wiper. This is contrary to the long standing, and incorrect, advice that the pot is wired to ground, Vcc and pin 3.

The RW pin (LCD pin 5)on the LCD should be connected to ground.

Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code. Posting in code tags prevents the forum software from changing your code to italics, for instance.